<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="author" content="featon inc.">
    <link rel="stylesheet" href="/static/vendor/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/vendor/bootstrap/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="/static/vendor/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/vendor/jqPagination/css/jqpagination.css">

    <link href="/static/vendor/jquery-easyui/themes/default/tree.css" rel="stylesheet">
    <link href="/static/vendor/jquery-easyui/themes/icon.css" rel="stylesheet">
    <link href="/static/vendor/jquery-ui/themes/base/jquery.ui.all.css" rel="stylesheet">

    <link rel="stylesheet" href="/static/vendor/skin/ftskin.css">

    <title>信息列表</title>
</head>

<body>
<div class="ft-subpage-wrapper container-fluid">

    <!-- 左导航开始	-->
    <div id="ftsidebar-subpage" style="overflow:auto;" class="ft-sidebar-box-subpage">
        <div class="leftTree-box">
            <ul id="leftTree" class="easyui-tree" animate="true">

            </ul>
        </div>
    </div>
    <!-- 左导航结束	-->

    <!-- 主窗口开始	-->
    <div id="ftmainBox" class="ft-mainBox">
        <div class="row">
            <div class="container-fluid">
                <div class="col-lg-12">
                    <div class="tools-box">
                        <button type="button" class="btn btn-info" onclick="openAddPage()"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 添加</button>
                        <button type="button" class="btn btn-warning" onclick="updateRecord(table,'user_id','openUpdatePage()');"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span> 修改</button>
                        <button type="button" class="btn btn-danger" onclick="deleteRecord(table,'user_id','deleteObject()');"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> 删除</button>
                        <button type="button" class="btn btn-info" onclick="updateRecord(table,'user_id','openSelectSinglDeptPage(\'选择组织机构\',\'moveObject\')');"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> 移动</button>
                        <!-- <button type="button" class="btn btn-info" onclick="publicSelectCheckbox(table,'user_id','openSelectSinglDeptPage(\'选择组织机构\',\'moveObject\')');"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> 移动</button> -->
                        <button type="button" class="btn btn-success" onclick="publicSelectCheckbox(table,'user_id','setUserStatus(0)');"><span class="glyphicon glyphicon-ok-circle" aria-hidden="true"></span> 启用</button>
                        <button type="button" class="btn btn-warning" onclick="publicSelectCheckbox(table,'user_id','setUserStatus(1)');"><span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span> 停用</button>
                        <button type="button" class="btn btn-info" onclick="updateRecord(table,'user_id','openSelectRole()');"><span class="glyphicon glyphicon-check" aria-hidden="true"></span> 关联角色</button>
                        <button type="button" class="btn btn-info" onclick="updateRecord(table,'user_id','updateUserpassword()');"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> 重置密码</button>



                    </div>
                </div>
            </div>
        </div>


        <div class="row">
            <div class="container-fluid">
                <div class="col-lg-12" id="table">

                </div>
            </div>
        </div>

        <div class="row">
            <div class="container-fluid">
                <div id="turn">

                </div>
            </div>
        </div>

    </div>
    <!-- 主窗口结束	-->
    <input type="hidden" th:id="dept_id" th:value="${dept_id}" />
</div>
<script src="/static/vendor/jquery/jquery-2.1.3.min.js"></script>
<script src="/static/vendor/bootstrap/js/bootstrap.min.js"></script>

<script src="/static/vendor/jquery-ui/minified/jquery-ui.min.js"></script>
<script src="/static/vendor/jquery-easyui/jquery.easyui.min.js"></script>

<link rel="stylesheet" href="/static/vendor/custom-scrollbar/jquery.mCustomScrollbar.min.css">
<script src="/static/vendor/custom-scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>

<script src="/static/vendor/jqPagination/js/jquery.jqpagination.min.js"></script>
<script src="/static/vendor/skin/js/ft-ui.js"></script>
<script src="/static/vendor/skin/js/tree-util.js"></script>
<script src="/static/vendor/skin/js/table-common.js"></script>
<script src="/static/vendor/skin/js/java.js"></script>
<script src="/static/vendor/skin/js/jquery.c.js"></script>
<script>
    var dept_id = $("#dept_id").val();
    var tp = new TurnPage();
    var table = new Table();
    table.table_name = "table_list";
    var beanList = null;
    var jsonData;
    var con_map = new Map();
    $(document).ready(function(){
        init_page();   //初始化页面内各BOX高度

        //table_input_init("dataTables-example-01"); //初始化input全选
        $("#ftsidebar-subpage").mCustomScrollbar({
            theme:"minimal-dark"
        });

        initTable();
        showDeptTree();
        loadListble();
    });

    $(window).resize(function(){
        init_page();
    });

    //初始化页面内各BOX高度
    function init_page()
    {
        var window_height = $(window).height();

        $("#ftmainBox").css("height",window_height-38);
        $("#ftsidebar-subpage").css("height",window_height-58);

    }

    function showDeptTree()
    {
        top.ajax.simple("/dept/getDeptTreeJsonStr/1",{},showDeptTreeHandl);
    }

    function showDeptTreeHandl(obj)
    {
        json_data = obj;
        setLeftMenuTreeJsonData(json_data);
        initMenuTree();
        treeNodeSelected(dept_id);
    }

    function initMenuTree()
    {
        $('#leftTree').tree({
            onClick:function(node){
                changeDeptListTable(node.id);
            }
        });

    }

    //点击树节点,修改用户列表数据
    function changeDeptListTable(m_id){
        dept_id = m_id;
        loadListble();
    }

    function initTable(){

        var colsMap = new Map();
        var colsList = new List();

        colsList.add(setTitleClos("user_name","登录名","120px","","",""));
        colsList.add(setTitleClos("action_col","操作","220px","","",""));
        colsList.add(setTitleClos("user_realname","真实姓名","100px","","",""));
        colsList.add(setTitleClos("user_phone","联系电话","100px","","",""));
        colsList.add(setTitleClos("user_status","用户状态","80px","","",""));
        colsList.add(setTitleClos("user_type","用户类型","100px","","",""));
        colsList.add(setTitleClos("dq_name","所属地区","80px","","",""));
        colsList.add(setTitleClos("role_name","关联角色","","","",""));

        table.setColsList(colsList);
        table.setAllColsList(colsList);
        table.enableSort=false;//禁用表头排序
        table.onSortChange = showList;
        table.show("table");//里面参数为外层div的id
    }

    function loadListble()
    {
        tp.curr_page = 1;
        showList();
        showTurnPage();
    }

    function showList(){
        con_map.put("dept_id", dept_id);
        //con_map.put("user_type", "1");
        con_map.put("start_num", tp.getStart());
        con_map.put("page_size", tp.pageSize);
        //con_map.put("orderby", "add_time desc");
        beanList = top.ajax.synclBody("/user/getUserList",con_map.toJSON())

        curr_bean = null;
        table.setBeanList(beanList,"td_list");//设置列表内容的样式
        table.show("table");


        table.getCol("action_col").each(function(i){
            if(i>0)
            {
                $(this).html('<a href="javascript:openUpdatePage(\''+beanList[i-1].user_id+'\')">编辑</a>&nbsp;&nbsp;<a href="javascript:deleteSingleObject(\''+beanList[i-1].user_id+'\')">删除</a>&nbsp;&nbsp;<a href="javascript:openSelectRole(\''+beanList[i-1].user_id+'\')">关联角色</a>&nbsp;&nbsp;<a href="javascript:updateUserpassword(\''+beanList[i-1].user_id+'\')">重置密码</a>');
            }
        });

        table.getCol("user_status").each(function(i){
            if(i>0)
            {
                if(beanList[i-1].user_status == 0)
                    $(this).text("正常");
                if(beanList[i-1].user_status == 1)
                    $(this).text("停用");
            }
        });

        table.getCol("user_type").each(function(i){
            if(i>0)
            {
                if(beanList[i-1].user_type == 0)
                    $(this).text("系统管理员");
                if(beanList[i-1].user_type == 1)
                    $(this).text("业务人员");
                if(beanList[i-1].user_type == 2)
                    $(this).text("监管对象");
            }
        });

        table.getCol("role_name").each(function(i){
            if(i>0)
            {
                if(beanList[i-1].role_name == null)
                    $(this).text("");
            }
        });
        table_input_init(table.table_name);
    }

    function showTurnPage(){
        tp.total = top.ajax.synclBody("/user/getUserCount",con_map.toJSON())
        tp.show("turn","");
        tp.onPageChange = showList;
    }

    function openAddPage()
    {

        var dept_id_num = parseInt(dept_id);
        if(dept_id_num < 2){
            modelWindow.waring(top.CMSLang.Select_Single_Dept);
            return;
        }
        top.addTab('/user/go_user_addFdept?dept_id='+dept_id);
    }

    function openUpdatePage(id)
    {
        var sel_id = '';
        if(id != '' && id != null)
        {
            sel_id = id;
        }else
            sel_id = table.getSelecteCheckboxValue("user_id");
        top.addTab("/user/go_user_addFdept?user_id="+sel_id);
    }

    //打开组织机构选择窗口
    function openSelectSinglDeptPage(title,handl_name,id)
    {
        var sel_id = '';
        if(id != '' && id != null)
        {
            sel_id = id;
        }else
            sel_id = table.getSelecteCheckboxValue("user_id");

        modelWindow.openFrameWindow(title,"/dept/go_select_single_dept?handle_name="+handl_name+"&user_id="+sel_id,450,410);
    }

    function moveObject(dept_id)
    {
        if(dept_id != "" && dept_id != null)
        {
            var selectIDS = table.getSelecteCheckboxValue("user_id");
            var move_m = new Map();

            move_m.put("dept_id",dept_id);
            move_m.put("user_id","'"+selectIDS.replace(/,/ig,"','")+"'");
            if(top.ajax.synclBody("/user/move",move_m.toJSON()))
            {
                modelWindow.alert("用户"+top.CMSLang.Move_success);
                loadListble();
            }else
            {
                modelWindow.error("用户"+top.CMSLang.Move_fail);
                return;
            }
        }
    }

    function deleteObject(id)
    {
        var sel_id = '';
        if(id != '' && id != null)
        {
            sel_id = id;
        }else
            sel_id = table.getSelecteCheckboxValue("user_id");

        var dm = new Map();
        dm.put("user_id","'"+sel_id.replace(/,/ig,"','")+"'");
        if(top.ajax.synclBody("/user/del",dm.toJSON()))
        {
            modelWindow.alert("用户信息"+top.CMSLang.Delete_success);
            loadListble();
        }else
        {
            modelWindow.error("用户信息"+top.CMSLang.Delete_fail);
        }
    }

    function deleteSingleObject(id)
    {
        modelWindow.confirm("是否删除该条记录","deleteObject('"+id+"')")
    }

    //修改人员状态
    function setUserStatus(status)
    {
        var selectIDS = table.getSelecteCheckboxValue("user_id");
        var om = new Map();
        om.put("user_status",status);
        om.put("user_id","'"+selectIDS.replace(/,/ig,"','")+"'");
        if(top.ajax.synclBody("/user/setUserStatus",om.toJSON()))
        {
            modelWindow.alert("用户状态"+top.CMSLang.Set_success);
            loadListble();
        }else
        {
            modelWindow.error("用户状态"+top.CMSLang.Set_fail);
            return;
        }
    }

    function openSelectRole(id)
    {
        var sel_id = '';
        if(id != '' && id != null)
        {
            sel_id = id;
        }else
            sel_id = table.getSelecteCheckboxValue("user_id");
        modelWindow.openFrameWindow("关联角色","/role/go_select_role?user_id="+sel_id,300,400);
    }

    function updateUserpassword(id)
    {
        var sel_id = '';
        if(id != '' && id != null)
        {
            sel_id = id;
        }else
            sel_id = table.getSelecteCheckboxValue("user_id");
        modelWindow.openFrameWindow("重置密码","/user/go_reload_pw?user_id="+sel_id,430,250);
    }
</script>
</body>
</html>
